from django.db import models


class EmpPosition(models.Model):
    post_code = models.CharField(max_length=50, null=True, blank=True, verbose_name='岗位编码')
    post_name = models.CharField(max_length=50, null=True, blank=True, verbose_name='岗位名称')
    post_status = models.BooleanField(default=True, verbose_name='岗位状态')
    create_time = models.DateTimeField(blank=True, null=True, auto_now_add=True, editable=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(blank=True, null=True, auto_now=True, editable=True, verbose_name='修改时间')

    def __str__(self):
        if self.post_status is True:
            return str(self.post_name)
        else:
            return str(self.post_name) + '(不再使用)'

    class Meta:
        managed = True
        db_table = 'emp_position'
        verbose_name_plural = '岗位表'
        verbose_name = '岗位表'


# Create your models here.

class EmpDepartment(models.Model):
    department_code = models.CharField(max_length=50, blank=True, null=True, verbose_name="部门编码")
    department_name = models.CharField(max_length=50, blank=True, null=True, verbose_name="部门名")
    department_full_name = models.CharField(max_length=255, blank=True, null=True, verbose_name="部门全称")
    department_short_name = models.CharField(max_length=50, blank=True, null=True, verbose_name="部门简称")
    department_manage_attr = models.CharField(max_length=50, blank=True, null=True, verbose_name="管理归属")
    department_level = models.IntegerField(blank=True, null=True, verbose_name="部门等级")
    parent = models.ForeignKey('self', blank=True, null=True, on_delete=models.DO_NOTHING, verbose_name='上级部门')
    create_time = models.DateTimeField(blank=True, null=True, auto_now_add=True, editable=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(blank=True, null=True, auto_now=True, editable=True, verbose_name='修改时间')

    def __str__(self):
        return self.department_name

    class Meta:
        managed = True
        db_table = 'emp_department'
        verbose_name_plural = '部门表'
        verbose_name = '部门表'


class EmpJobDuty(models.Model):
    job_duty_code = models.CharField(max_length=50, null=True, blank=True, verbose_name='职务编码')
    job_duty_name = models.CharField(max_length=50, null=True, blank=True, verbose_name='职务名称')
    job_duty_status = models.BooleanField(default=True, verbose_name='职务状态')
    job_duty_class = models.ForeignKey(to='employee.EmpJobClass', on_delete=models.SET_NULL, null=True, blank=True, verbose_name='职等', db_constraint=False)
    job_duty_grade = models.ForeignKey(to='employee.EmpJobGrade', on_delete=models.SET_NULL, null=True, blank=True, verbose_name='职级', db_constraint=False)
    create_time = models.DateTimeField(blank=True, null=True, auto_now_add=True, editable=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(blank=True, null=True, auto_now=True, editable=True, verbose_name='修改时间')

    def __str__(self):
        if self.job_duty_status is True:
            return str(self.job_duty_name)
        else:
            return str(self.job_duty_name) + '(不再使用)'

    class Meta:
        managed = True
        db_table = 'emp_job_duty'
        verbose_name_plural = '职务表'
        verbose_name = '职务表'


class EmpJobGrade(models.Model):
    job_grade_code = models.CharField(max_length=50, null=True, blank=True, verbose_name='职级编码')
    job_grade_name = models.CharField(max_length=50, null=True, blank=True, verbose_name='职级名称')
    job_grade_status = models.BooleanField(default=True, verbose_name='职级状态')
    create_time = models.DateTimeField(blank=True, null=True, auto_now_add=True, editable=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(blank=True, null=True, auto_now=True, editable=True, verbose_name='修改时间')

    def __str__(self):
        if self.job_grade_status is True:
            return str(self.job_grade_name)
        else:
            return str(self.job_grade_name) + '(不再使用)'

    class Meta:
        managed = True
        db_table = 'emp_job_grade'
        verbose_name_plural = '职级表'
        verbose_name = '职级表'


class EmpJobClass(models.Model):
    job_class_code = models.CharField(max_length=50, null=True, blank=True, verbose_name='职等编码')
    job_class_name = models.CharField(max_length=50, null=True, blank=True, verbose_name='职等名称')
    job_class_status = models.BooleanField(default=True, verbose_name='职等状态')
    create_time = models.DateTimeField(blank=True, null=True, auto_now_add=True, editable=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(blank=True, null=True, auto_now=True, editable=True, verbose_name='修改时间')

    def __str__(self):
        if self.job_class_status is True:
            return str(self.job_class_name)
        else:
            return str(self.job_class_name) + '(不再使用)'

    class Meta:
        managed = True
        db_table = 'emp_job_class'
        verbose_name_plural = '职等表'
        verbose_name = '职等表'


class EmpJobRank(models.Model):
    job_rank_code = models.CharField(max_length=50, null=True, blank=True, verbose_name='合同归属编号')
    job_rank_name = models.CharField(max_length=50, null=True, blank=True, verbose_name='合同归属名称')
    job_rank_status = models.BooleanField(default=True, verbose_name='合同归属状态')
    create_time = models.DateTimeField(blank=True, null=True, auto_now_add=True, editable=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(blank=True, null=True, auto_now=True, editable=True, verbose_name='修改时间')

    def __str__(self):
        if self.job_rank_status is True:
            return str(self.job_rank_name)
        else:
            return str(self.job_rank_name) + '(不再使用)'

    class Meta:
        managed = True
        db_table = 'emp_job_rank'
        verbose_name_plural = '合同归属表'
        verbose_name = '合同归属表'


class EmpPayType(models.Model):
    pay_type_code = models.CharField(max_length=50, null=True, blank=True, verbose_name='计薪编码')
    pay_type_name = models.CharField(max_length=50, null=True, blank=True, verbose_name='计薪名称')
    pay_type_status = models.BooleanField(default=True, verbose_name='计薪方式状态')
    create_time = models.DateTimeField(blank=True, null=True, auto_now_add=True, editable=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(blank=True, null=True, auto_now=True, editable=True, verbose_name='修改时间')

    def __str__(self):
        if self.pay_type_status is True:
            return str(self.pay_type_name)
        else:
            return str(self.pay_type_name) + '(不再使用)'

    class Meta:
        managed = True
        db_table = 'emp_pay_type'
        verbose_name_plural = '计薪方式表'
        verbose_name = '计薪方式表'
